package com.janushuang.algorithm.sort;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zhijing.huang
 *         Created by zhijing.huang on 2014/9/26.
 */
public class BubbleSort implements Sort {
    private static final Logger LOG = LoggerFactory.getLogger(BubbleSort.class);

    @Override
    public void sort(int[] data) {
        int loopCount=0;
        for (int i = 0; i < data.length; i++) {
            ++loopCount;
            for (int j = data.length-1; j > i; j--) {
                ++loopCount;
                if(data[j]<data[j-1]) {
                    SortUtils.swap(data,j,j-1);
                }
            }
        }
//        LOG.info("loopCount={}",loopCount);
    }
}
